package com.proxyadvertise;

import java.util.List;

import com.proxyadvertise.parse.ConfigFile;
import com.proxyadvertise.parse.ProxyIp;
import com.proxyadvertise.parse.RegistryManager;
import com.proxyadvertise.parse.UserAgent;
import com.proxyadvertise.view.IEFrame;

public class VisitUrl {
	
	public VisitUrl(){
		
	}
	
	public void visit( int visitCount ){
		
		String url = ConfigFile.getConfigValue( "main_url" );
		System.out.println( url );
		
		IEFrame ie = new IEFrame( url );
			
		//每一个ip访问次数
		for( int i=0;i<visitCount;i++ ){			
			ie.open();			
		}
		
		ie.close();
		 
	}
	
	public static void main(String[] args) {
		
		//初始化
		try {
			ProxyIp.parse();
			UserAgent.parse();
			ConfigFile.parse();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		int visitCount = Integer.parseInt( ConfigFile.getConfigValue( "visitCount" ) );
		List<String> allProxyIp = ProxyIp.getAllProxyIp();
		
		//所有代理Ip
		for( String ip : allProxyIp ){
			
			try {
				System.out.println( "代理ip为："+ip );
				//设置ie代理ip
				RegistryManager.setProxyIp( ip );
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			//每一个ip访问次数
			VisitUrl u = new VisitUrl();
			u.visit( visitCount );
			
		}
		
		try {
			
			//重置代理
			RegistryManager.clearProxy();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
